package job

import (
	"github.com/go-admin-team/go-admin-core/logger"
	"github.com/go-admin-team/go-admin-core/sdk/pkg"
	"github.com/robfig/cron/v3"
	"strings"
	"vrcm/src/vrcm/app/admin/models"
	domianService "vrcm/src/vrcm/app/admin/service/domian"
	"vrcm/src/vrcm/app/admin/service/dynamic"
	service "vrcm/src/vrcm/app/admin/service/likes"
	scheduleService "vrcm/src/vrcm/app/admin/service/live_schedule"
	"vrcm/src/vrcm/sdk"
)

func InitJob() {
	like := service.Likes{}
	channelTaskService := scheduleService.ChannelTaskService{}
	sourceBasicService := scheduleService.SourceBasicService{}
	domainService := domianService.DomainConfig{}
	dynamicService := dynamic.DynamicServer{}
	like.Redis = sdk.Runtime.GetCacheAdapter()
	dbs := sdk.Runtime.GetDb()
	log := logger.NewHelper(sdk.Runtime.GetLogger()).WithFields(map[string]interface{}{
		strings.ToLower(pkg.TrafficKey): "",
	})

	for _, v := range dbs {
		like.Orm = v
		channelTaskService.Orm = v
		sourceBasicService.Orm = v
		channelTaskService.Log = log
		sourceBasicService.Log = log
		domainService.Orm = v
		domainService.Log = log
		dynamicService.Orm = v
		dynamicService.Log = log
	}

	c := cron.New(cron.WithSeconds())
	//c.AddFunc(models.Likes_Corn, like.SyncLikesNum)
	c.AddFunc(models.Likes_Corn, channelTaskService.TimeStartWorkflow)
	//c.AddFunc(models.Likes_Corn, sourceBasicService.TimeStopEquip)
	c.AddFunc(models.State_Corn, domainService.TimeRefreshHotState)
	c.AddFunc(models.Dynamic_State_Corn, dynamicService.TimeRefreshTaskState)
	//c.AddFunc(models.Likes_Corn, sourceBasicService.TimeDeleteCustomSource)
	//c.AddFunc(models.Likes_Corn, sourceBasicService.TimeStartSource)
	go c.Start()
	defer c.Stop()
}
